<?php

/**
 * Name: 员工模型层
 * User: Silent
 * Date: 2025-09-20
 * Time: 22:44:45
 */

namespace App\Models\Config;

use App\Models\Auth\WechatUser;
use DateTimeInterface;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;

class Employee extends Model
{
    use HasFactory, SoftDeletes;

    protected $table = 'employees';

    protected $guarded = [];

    protected $casts = [
        'created_at' => 'datetime:Y-m-d H:i:s',
        'updated_at' => 'datetime:Y-m-d H:i:s',
        'deleted_at' => 'datetime:Y-m-d H:i:s',
    ];

    protected static $logName = 'employees';

    protected function serializeDate(DateTimeInterface $date): string
    {
        return $date->format('Y-m-d H:i:s');
    }

    /**
     * 关联微信用户 - 通过wechat_user_id关联到wechat_user表的id
     */
    public function wechatUser()
    {
        return $this->belongsTo(WechatUser::class, 'wechat_user_id', 'id');
    }

    /**
     * 关联微信用户 - 通过userid关联（企业微信userid）
     */
    public function wechatUserByUserid()
    {
        return $this->belongsTo(WechatUser::class, 'userid', 'userid');
    }

}
